package demo.using.threadPool;

/**
 * @author : GuoFei
 * @since : 2019/7/6 9:44
 */
public class TestMain6 {

    public static ThreadLocal<String> threadLocal = new ThreadLocal<>();

    public static void main(String[] args) throws InterruptedException {
        System.out.println("main thread put value");
        threadLocal.set("I am main thread : I am main thread");
        new Thread(()->{
            System.out.println("other thread get value :"+threadLocal.get());
            System.out.println("other thread put value : I am other thread");
            threadLocal.set("I am other thread");
            try {
                System.out.println("other thread sleep 5s");
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("other thread get value :"+threadLocal.get());
            System.out.println("other thread remove value");
            threadLocal.remove();
        }).start();
        Thread.sleep(1000);
        System.out.println("main thread get value :"+threadLocal.get());
        System.out.println("main thread remove value");
        threadLocal.remove();
        System.out.println("main thread get value :"+threadLocal.get());
    }


}
